package com.piece.core.web.authority.token;

import com.piece.core.framework.constant.ParamConstants;
import org.springframework.security.core.Authentication;
import javax.servlet.http.HttpServletRequest;

public abstract class CompositeAuthorizationGranter {

    public String grantType;

    public CompositeAuthorizationGranter(String grantType) {
        this.grantType = grantType;
    }

    public Authentication get(HttpServletRequest request) {
        if (!support(request.getParameter(ParamConstants.GRANT_TYPE))) {
            return null;
        }

        return grant(request);
    }

    public abstract Authentication grant(HttpServletRequest request);

    private boolean support(String type) {
        return type.equalsIgnoreCase(this.grantType);
    }
}
